package cn.com.nes.site.service.system.company.impl;

import cn.com.nes.mybatis.callcenter.entity.CcCompany;
import cn.com.nes.mybatis.callcenter.mapper.CcCompanyMapper;
import cn.com.nes.site.entity.vo.system.ClientRegisterInfo;
import cn.com.nes.site.service.system.company.CcCompanyService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CcCompanyServiceImpl implements CcCompanyService {
    @Resource
    private CcCompanyMapper ccCompanyMapper;

    @Override
    public List<CcCompany> selectList() {
        QueryWrapper<CcCompany> wrapper = new QueryWrapper<>();
        wrapper.eq("is_delete", 0);
        return ccCompanyMapper.selectList(wrapper);
    }

    @Override
    public boolean checkClientRegisterInfo(String appId, String appSecret) {
        if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(appSecret)) {
            return false;
        }
        if (appId.startsWith("extern")) {
            return true;
        }
        ClientRegisterInfo clientRegisterInfo = ccCompanyMapper.getClientRegisterInfoByAppId(appId);
        if (clientRegisterInfo == null) {
            return false;
        }
        if (appSecret.equals(clientRegisterInfo.getAppSecret())) {
            return true;
        }
        return false;
    }
}
